package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/3/7 17:45
 * @description
 */
public class Code848 {
    public static void main(String[] args) {
        System.out.println(new Code848().shiftingLetters("gdhbjaph", new int[] {74, 34, 65, 30, 43, 91, 14, 10}));
    }

    public String shiftingLetters(String S, int[] shifts) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < shifts.length; i++) {
            int sum = shifts[i] % 26;
            for (int j = i + 1; j < shifts.length; j++) {
                sum += shifts[j] % 26;
            }
            shifts[i] = sum % 26;
        }
        char[] cs = S.toCharArray();
        for (int i = 0; i < cs.length; i++) {
            char c = cs[i];
            if (shifts.length > i) {
                int num = shifts[i];
                if (c + num > 122) {
                    c = (char)(c - 26 + num);
                } else {
                    c += num;
                }
            }
            sb.append(c);
        }
        return sb.toString();
    }
}
